2 to 3 onions, thinly sliced (2 heaping cups)
¼ cup extra-virgin olive oil, more for drizzling
Salt and freshly cracked black pepper
1 ½ pounds ripe tomatoes, seeded and cut into strips about 3/8-inch wide
1 2-ounce can anchovies packed in olive oil, drained (reserve anchovies and oil separately)
2 large cloves garlic, smashed and peeled
1 tablespoon fresh herbs, such as thyme, oregano or savory, or 1 teaspoon dried herbes de Provence
About 2 pounds thin-skinned, waxy potatoes like Yukon Gold, sliced 1/8-inch thick (6 to 7 cups)
½ cup grated Parmigiano-Reggiano or Gruyère
Heat oven to 400 degrees and place a rack at the middle level. In a large saucepan, combine onions and 2 tablespoons olive oil and stir to coat over low heat. Sprinkle lightly with salt. At a gentle simmer, cook uncovered until onions are softened and lightly golden, 10 to 15 minutes, stirring often. Do not brown; lower the heat if necessary. When done, fold in tomatoes just until heated through. Set aside.
In a small food processor or a mortar, add the anchovies — anywhere from 6 to 12 fillets, depending on their size and your taste. Add garlic, herbs and a dozen grinds of pepper. Add 2 tablespoons olive oil (or use the oil from the anchovy can, if you like). Crush or pulse together into a chunky paste, thinning with oil as needed to make a loose, fluid mixture.
In a medium-size baking dish, spread a quarter of the onion-tomato mixture. On top, arrange half the potato slices, then half the anchovy mixture. Add half the remaining onion-tomato mixture. Build one more layer with remaining potato slices, anchovy mixture and onion-tomato mixture. Sprinkle cheese on top and drizzle with olive oil.
If the dish is very full, place on a baking sheet. Transfer to oven and bake, uncovered, until potatoes are tender and have absorbed all of the juices in the bottom of the dish, 40 to 50 minutes. Test by tasting a bit of potato; it should be soft all the way through, with no raw taste. If the top is browning too fast, cover very loosely with a sheet of foil. If the top is not brown enough when the potatoes are cooked, broil briefly until deliciously glazed.
Serve gratin hot or warm. Can be cooled and reheated later the same day, but do not refrigerate.